package com.jmgd.cjlx.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws ParseException {
        List<Map<String, Object>> data = new ArrayList<>();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, Object> map1 = new HashMap<>();
        map1.put("id", 1);
        map1.put("name", "Bob");
        map1.put("date", sdf.parse("2024-12-16"));

        Map<String, Object> map2 = new HashMap<>();
        map2.put("id", 2);
        map2.put("name", "Bob1");
        map1.put("date", sdf.parse("2024-12-12"));

        Map<String, Object> map3 = new HashMap<>();
        map3.put("id", 3);
        map3.put("name", "Bob");
        map1.put("date", sdf.parse("2024-12-14"));

        data.add(map1);
        data.add(map2);
        data.add(map3);
        // 例如，我们根据 id 查找 name 为 Bob 的记录
        String searchName = "Bob";
        int searchId = 1;

        Date searchDate = sdf.parse("2024-12-14");
        List<Map<String, Object>> result = data.stream()
                .filter(row -> searchName.equals(row.get("name")))  // 筛选出 name 为 Bob 的行
               // .filter(row -> Objects.equals(row.get("id"), searchId))  // 比较 id 字段
                .filter(row -> row.get("date") instanceof Date &&
                        ((Date) row.get("date")).equals(searchDate))  // 日期比较
                .collect(Collectors.toList());  // 收集所有符合条件的结果到一个 List 中

        System.out.println(result);  // 输出所有符合条件的记录

    }
}
